﻿package util 
{
	import flash.display.DisplayObject;
	import flash.display.GradientType;
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.geom.Matrix;
	
	/**
	 * ...
	 * @author kasoi
	 */
	public class DrawUtils 
	{
		
		public function DrawUtils() 
		{
			
		}
		
		static public function drawTriangle(width: Number, height: Number, color: Number, rotation: Number) : Sprite
		{
			var spr: Sprite = new Sprite();
			spr.graphics.beginFill(color, 1);
			spr.graphics.lineStyle(0, 0, 0);
			spr.graphics.lineTo(width, 0);
			spr.graphics.lineTo(width / 2, height);
			spr.graphics.lineTo(0, 0);
			
			return spr;
		}
		
		static public function drawDottedLoader(diameter: Number, dotMaxSize: Number = 10, dotsNum: int = 10, color: Number = 0xffffff) : Sprite
		{
			var spr: Sprite = new Sprite();
			for (var i: int = 0; i < dotsNum; i++) 
			{
				var r: Number = (360 / dotsNum) * i;
				var toX: Number = (diameter / 2) * Math.sin(r * Math.PI / 180);
				var toY: Number = (diameter / 2) * Math.cos(r * Math.PI / 180);
				var s: Number = (dotMaxSize / dotsNum) * (dotsNum - i);
				var dot: Shape = new Shape();
				dot.graphics.beginFill(color, 1);
				dot.graphics.drawCircle(toX, toY, s / 2);
				dot.graphics.endFill();
				spr.addChild(dot);
			}
			return spr;
		}
		
		static public function drawCatalystBlueLine(w: Number, h: Number, g: Graphics) : void 
		{
			var matrix: Matrix = new Matrix();
			matrix.createGradientBox(w, h, 90 * Math.PI / 180);
			
			g.clear();
			g.beginGradientFill(GradientType.LINEAR,
				[0x2e8bcd, 0x1b6599], [1, 1], [15, 160], matrix);
			g.drawRect(0, 0, w, h);
			g.endFill();
		}
		
		static public function drawGradientLine(w: Number, h: Number, r: Number, 
			colors: Array, alphas: Array, ratios: Array) : Sprite
		{
			var spr: Sprite = new Sprite();
			var g: Graphics = spr.graphics;
			var matrix: Matrix = new Matrix();
			matrix.createGradientBox(w, h, r * Math.PI / 180);
			
			g.beginGradientFill(GradientType.LINEAR,
				colors, alphas, ratios, matrix);
			g.drawRect(0, 0, w, h);
			g.endFill();
			
			return spr;
		}
	}
	
}